package com.hruiworks.campusgroup.controller;

import com.hruiworks.campusgroup.common.BaseResponse;
import com.hruiworks.campusgroup.common.PageVO;
import com.hruiworks.campusgroup.enums.SuccessCode;
import com.hruiworks.campusgroup.pojo.entity.Activity;
import com.hruiworks.campusgroup.pojo.query.ActivityPageQuery;
import com.hruiworks.campusgroup.pojo.query.ActivityQuery;
import com.hruiworks.campusgroup.service.ActivityService;
import com.hruiworks.campusgroup.utils.ResultUtils;
import com.hruiworks.usercheck.exception.UserCheckException;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author jiushui
 * 用于测试
 */
@RestController
@RequestMapping("/api/test")
public class TestController {

    @Resource
    private ActivityService activityService;

    @GetMapping("/exception")
    public BaseResponse<Object> exceptionTest() {
        throw new UserCheckException("1");
    }

    @PostMapping("/activity/list")
    public BaseResponse<List<Activity>> test(@RequestBody ActivityQuery activityQuery) {
        List<Activity> activities = activityService.listActivity(activityQuery);
        return ResultUtils.success(activities, SuccessCode.COMMON_SUCCESS);
    }

    @PostMapping("/activity/page")
    public BaseResponse<PageVO<Activity>> test(@RequestBody ActivityPageQuery activityPageQuery) {
        PageVO<Activity> activityPageVO = activityService.listPageActivity(activityPageQuery);
        return ResultUtils.success(activityPageVO, SuccessCode.COMMON_SUCCESS);
    }
}
